package cn.edu.tju.elm.model;

/**
 * 订单状态枚举
 * 定义订单可能的所有状态
 */
public enum OrderStatus {
    PENDING_PAYMENT(0, "待支付"),
    PAID(1, "已支付"),
    DELIVERING(2, "配送中"),
    COMPLETED(3, "已完成"),
    CANCELLED(4, "已取消");
    
    private final int value;
    private final String displayName;
    
    OrderStatus(int value, String displayName) {
        this.value = value;
        this.displayName = displayName;
    }
    
    public int getValue() {
        return value;
    }
    
    public String getDisplayName() {
        return displayName;
    }
    
    /**
     * 根据整数值获取对应的枚举常量
     * @param value 状态值
     * @return 对应的OrderStatus枚举
     * @throws IllegalArgumentException 如果值无效
     */
    public static OrderStatus fromValue(int value) {
        for (OrderStatus status : values()) {
            if (status.value == value) {
                return status;
            }
        }
        throw new IllegalArgumentException("无效的订单状态值: " + value);
    }
    
    /**
     * 检查状态是否允许删除订单
     * @return 如果状态允许删除返回true
     */
    public boolean canDelete() {
        return this == PENDING_PAYMENT || this == CANCELLED;
    }
    
    @Override
    public String toString() {
        return displayName;
    }
}